package org.usmile.algorithms.huawei.acm;

import java.util.*;

// https://blog.csdn.net/qq_34465338/article/details/128478461
public class _最少数量线段覆盖 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        sc.nextLine();
        int[][] segments = new int[n][2];
        for (int i = 0; i < n; i++) {
            String[] numsStr = sc.nextLine().split(",");
            segments[i] = new int[]{Integer.parseInt(numsStr[0]), Integer.parseInt(numsStr[1])};
        }
        Arrays.sort(segments, (o1, o2) -> o1[0] == o2[0] ? o1[1] - o2[1] : o1[0] - o2[0]);

        Map<Integer, Integer> lineMap = new HashMap<>();
        for (int i = 0; i < n; i++) {
            for (int j = segments[i][0]; j <= segments[i][1]; j++) {
                lineMap.put(j, lineMap.getOrDefault(j, 0) + 1);
            }
        }

        int deleteCount = 0;
//        List<int[]> deleted = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            boolean canDelete = true;
            for (int j = segments[i][0]; j <= segments[i][1]; j++) {
                if (lineMap.get(j) <= 1) {
                    canDelete = false;

                    break;
                }
            }

            if (canDelete) {
//                deleted.add(segments[i]);
                for (int j = segments[i][0]; j <= segments[i][1]; j++) {
                    lineMap.put(j, lineMap.get(j) - 1);
                }

                deleteCount++;
            }
        }

//        System.out.println(deleted);
        System.out.println(n - deleteCount);
    }
}
